const sharp = require('sharp');
const path = require('path');
const fs = require('fs');

const images = [
  { name: 'banner1.jpg', w: 750, h: 300, color: '#e0e0e0', text: 'BANNER 1' },
  { name: 'banner2.jpg', w: 750, h: 300, color: '#d0eaff', text: 'BANNER 2' },
  { name: 'banner3.jpg', w: 750, h: 300, color: '#ffe0e0', text: 'BANNER 3' },
  { name: 'category1.png', w: 160, h: 160, color: '#f5c542', text: '分类1' },
  { name: 'category2.png', w: 160, h: 160, color: '#42c5f5', text: '分类2' },
  { name: 'category3.png', w: 160, h: 160, color: '#a1e842', text: '分类3' },
  { name: 'category4.png', w: 160, h: 160, color: '#e842a1', text: '分类4' },
  { name: 'service1.jpg', w: 300, h: 200, color: '#cccccc', text: '服务1' },
  { name: 'service2.jpg', w: 300, h: 200, color: '#cccccc', text: '服务2' },
  { name: 'order-empty.png', w: 180, h: 180, color: '#f5f5f5', text: '暂无订单' },
  { name: 'avatar.png', w: 100, h: 100, color: '#e0e0e0', text: '头像' },
  { name: 'tabbar/home.png', width: 72, height: 72, color: '#bdbdbd', text: '首页' },
  { name: 'tabbar/home-selected.png', width: 72, height: 72, color: '#1aad19', text: '首页' },
  { name: 'tabbar/group.png', width: 72, height: 72, color: '#bdbdbd', text: '团购' },
  { name: 'tabbar/group-selected.png', width: 72, height: 72, color: '#1aad19', text: '团购' },
  { name: 'tabbar/order.png', width: 72, height: 72, color: '#bdbdbd', text: '订单' },
  { name: 'tabbar/order-selected.png', width: 72, height: 72, color: '#1aad19', text: '订单' },
  { name: 'tabbar/user.png', width: 72, height: 72, color: '#bdbdbd', text: '我的' },
  { name: 'tabbar/user-selected.png', width: 72, height: 72, color: '#1aad19', text: '我的' }
];

const outDir = path.join(__dirname, 'images');
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir);

async function createPlaceholder({ name, w, h, color, text }) {
  const svg = `<svg width='${w}' height='${h}' xmlns='http://www.w3.org/2000/svg'><rect width='100%' height='100%' fill='${color}'/><text x='50%' y='50%' font-size='32' fill='#888' text-anchor='middle' alignment-baseline='middle' font-family='Arial'>${text}</text></svg>`;
  const buffer = Buffer.from(svg);
  const outPath = path.join(outDir, name);
  await sharp(buffer).resize(w, h).toFile(outPath);
  console.log('Generated', outPath);
}

(async () => {
  for (const img of images) {
    await createPlaceholder(img);
  }
})(); 